import unittest
from HTMLTestRunner import HTMLTestRunner

import time
test_dir='./test_case'  #测试用例存放位置

discover=unittest.defaultTestLoader.discover(test_dir,pattern="test*.py")

if __name__ == '__main__':

    report_dir='./test_report'
    ##测试报告存放位置
    now=time.strftime("%Y-%m-%d %H_%M_%S")
    # time.strftime(format='')
    ##时间戳
    report_name=report_dir+'/'+now+'result.html'

    ##文件命名
    # with open (报告名,wb) as f:   报告名就是路径
        # HTMLTestRunner.run()
        # f.close()
    with open(report_name,'wb') as f:
        # runner=HTMLTestRunner(stream=f,title="Test Report",description="test ERP")
        HTMLTestRunner(stream=f,title='Test Report',description='test ERP').run(discover)
        # runner.run(discover)
    f.close()